Learning Flex Basics (Part 1): Creating Your First Flex Application
Robert Crooks
Table of Contents
- Introduction
- A Brief Overview of Macromedia Flex
- Building the Application
- Create the Application Object
- Add a Panel for the Application Layout
- Add a Label for the View Header
- Add an Array of Objects to Define the Coffee Blends
- Add a ComboBox to Display the Coffee Blends
- Add a Text Control to Display the Description
- Add a Button to Add a Coffee Blend to the Shopping Cart
- Add a List Control for the Shopping Cart
- Add a Script to Handle the Button Click Event
- Complete Code Listing for firstapp.mxml
- Where to Go From Here
In this tutorial you will learn the basic elements of Macromedia Flex applications through an overview and through building a simplified catalog and shopping cart in MXML. To do this you will create an application, add a layout container, add controls, create a simple data model that is bound to controls, and finally create event-handler functions in ActionScript.
This tutorial is the first part in a four-part series written by Robert Crooks of the Macromedia Customer Training group:
- Learning Flex Basics (Part 2): Creating a Flex Calculator
- Learning Flex Basics (Part 3): Working with Containers
- Learning Flex Basics (Part 4): Working with Data Models
If you prefer, you can download the entire set of tutorials.
-
Learning
Flex Series (Parts 1-4) (144 KB)
If you like what you see and want to get more experience with Flex, Macromedia Customer Training offers Fast Track to Macromedia Flex, a two-day onsite training course to jump-start Flex development in your organization. Now let's get started!
If you are new to writing XML languages, remember these basic rules:
- Both tag and attribute names in MXML, as in all XML languages is case-sensitive
- All values for attributes must be in single or double quotation marks
- All tags must be closed. Tags that contain no nested tags or content can be closed with a simple slash rather than a full end tag:
<mx:Label text="Hello"></mx:Label> or <mx:Label text="Hello"/>
If you are new to ActionScript, you will probably find the syntax similar to languages you already know, such as JavaScript or Java. Remember these basic rules:
- ActionScript is case-sensitive
- Statements are terminated by a semi-colon (;)
What You Will Learn:
- Get a brief overview of Flex
- How to use the Application tag.
- How to use a Panel container.
- How to use a Label control.
- How to use a Text control.
- How to use Button controls.
- How to use a ComboBox control.
- How to create an array of objects.
- How to bind data to controls.
- How to create an ActionScript handler for a user event.
Requirements
To complete this tutorial you will need to install the following software and files:
Macromedia Flex
(Installed and running on any server and platform supported by Flex. Note that the Flex trial is available on CD from the Macromedia store for $8.99. To learn more about the Flex trial, please read the Flex Frequently Asked Questions.)
Dreamweaver MX 2004 or a text editor that you can use to write XML and ActionScript code (a basic text editor such as Notepad is adequate)
Solution files for this tutorial:
firstapp.zip
contains the complete source code for firstapp.mxml
within this article.
Prerequisite knowledge:
- Read A Brief Overview of Flex.
- You must know how to browse a Flex application.